## Power Sharing, Presidential Style

library(dplyr)
library(survival)
library(stargazer)
library(rms) 
library(margins)
library(dotwhisker)
library(ggpubr)
library(grid)



load("Data_ComparativeAnalysis.Rda")


#### Main Models

cle0<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism +strata(ID), method=,data=min3)
cle1<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Aligned*Salience +strata(ID),data=min3)
cle3<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Seat.Share*Salience +strata(ID),data=min3)
cle5<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Clientelism*Salience +strata(ID),data=min3)


stargazer(cle0, cle1,cle3,cle5, title="Portfolio Allocation", type="html",out="CLMainExt.doc")


#### Robustness Checks 

## Core Ministries

cle1<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Aligned*Coord +strata(ID),data=min3)
cle2<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Seat.Share*Coord +strata(ID),data=min3)
cle3<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Clientelism*Coord +strata(ID),data=min3)

stargazer(cle1,cle2,cle3, title="Portfolio Allocation", type="html",out="CLRobustnessExtC.doc")


## President's Party X Non-Partisan

cle4<-clogit(AppointedMin ~ as.factor(Status2)  + Seat.Share + Clientelism +strata(ID),data=min3)
cle5<-clogit(AppointedMin ~ as.factor(Status2)  + Seat.Share + Clientelism + as.factor(Status2)*Salience +strata(ID),data=min3)
cle6<-clogit(AppointedMin ~ as.factor(Status2)  + Seat.Share + Clientelism + Seat.Share*Salience +strata(ID),data=min3)
cle7<-clogit(AppointedMin ~ as.factor(Status2)  + Seat.Share + Clientelism + Clientelism*Salience +strata(ID),data=min3)


stargazer(cle4, cle5, cle6, cle7, title="Portfolio Allocation", type="html",out="CLRobustnessExtS.doc")


#### Supplementary Material

## Main Models with Contextual Factors


cle2<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Aligned*Salience  + Aligned*Popularity + Aligned*Inflation + Aligned*Leg.Cohesion +strata(ID),data=min3)
cle4<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Seat.Share*Salience +Seat.Share*Popularity +Seat.Share*Inflation  + Seat.Share*Leg.Cohesion +strata(ID), data=min3)
cle6<-clogit(AppointedMin ~ Aligned  + Seat.Share + Clientelism + Clientelism*Salience + Clientelism*Popularity + Clientelism*Inflation + Clientelism*Leg.Cohesion +strata(ID), data=min3)


stargazer(cle2,cle4,cle6, title="Portfolio Allocation", type="html",out="CLRobustnessExtSM.doc")



### Countries

minbr<- min3[ which(min3$Country == "bra"), ]
minchi<- min3[ which(min3$Country == "chi"), ]
mincol<- min3[ which(min3$Country == "col"), ]

#BR

clebr0<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism +strata(ID), method=,data=minbr)
clebr1<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Aligned*Salience +strata(ID),data=minbr)
clebr2<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Seat.Share*Salience +strata(ID),data=minbr)
clebr3<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Clientelism*Salience +strata(ID),data=minbr)


#Chi

clechi0<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism +strata(ID), method=,data=minchi)
clechi1<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Aligned*Salience +strata(ID),data=minchi)
clechi2<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Seat.Share*Salience +strata(ID),data=minchi)
clechi3<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Clientelism*Salience +strata(ID),data=minchi)



#Col

clecol0<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism +strata(ID), method=,data=mincol)
clecol1<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Aligned*Salience +strata(ID),data=mincol)
clecol2<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Seat.Share*Salience +strata(ID),data=mincol)
clecol3<-clogit(AppointedMin ~ Aligned + Seat.Share + Clientelism + Clientelism*Salience +strata(ID),data=mincol)

stargazer(clebr1,clebr2,clebr3, clechi1,clechi2,clechi3, clecol1,clecol2,clecol3, title="Portfolio Allocation", type="html",out="CLCountries.doc")


summary(clebr1)
##



m1_df <- broom::tidy(clebr1)  %>% mutate(model = "Model 1")
m2_df <- broom::tidy(clechi1)  %>% mutate(model = "Model 2")
m3_df <- broom::tidy(clecol1)  %>% mutate(model = "Model 3")

m4_df<- rbind(m1_df, m2_df, m3_df)
m4_df <- m4_df[-c(4,9,14), ]

dw1<-dwplot(m4_df, dot_args = list(aes(shape = model)),
            whisker_args = list(aes(linetype = model)))+
  geom_vline(xintercept = 0, colour = "red", linetype = 2) + 
  theme_bw() + xlab("Coefficient Estimate") +
  theme(legend.position = "top") +
scale_colour_grey(start = .1, end = .1, name = "Model", labels = c("Brazil", "Chile", "Colombia")) +
  scale_shape_discrete(name = "Model",labels = c("Brazil", "Chile", "Colombia")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model")) +
  theme(axis.text=element_text(size=14))+
  theme(legend.text = element_text(size=14))


#

m1_df <- broom::tidy(clebr2)  %>% mutate(model = "Model 1")
m2_df <- broom::tidy(clechi2)  %>% mutate(model = "Model 2")
m3_df <- broom::tidy(clecol2)  %>% mutate(model = "Model 3")

m4_df<- rbind(m1_df, m2_df, m3_df)
m4_df <- m4_df[-c(4,9,14), ]

dw2<-dwplot(m4_df, dot_args = list(aes(shape = model)),
            whisker_args = list(aes(linetype = model)))+
  geom_vline(xintercept = 0, colour = "red", linetype = 2) + 
  theme_bw() + xlab("Coefficient Estimate") +
  theme(legend.position = "top") +
  scale_colour_grey(start = .1, end = .1, name = "Model", labels = c("Brazil", "Chile", "Colombia")) +
  scale_shape_discrete(name = "Model",labels = c("Brazil", "Chile", "Colombia")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model")) +
  theme(axis.text=element_text(size=14)) +
  theme(legend.text = element_text(size=14))


# 

m1_df <- broom::tidy(clebr3)  %>% mutate(model = "Model 1")
m2_df <- broom::tidy(clechi3)  %>% mutate(model = "Model 2")
m3_df <- broom::tidy(clecol3)  %>% mutate(model = "Model 3")

m4_df<- rbind(m1_df, m2_df, m3_df)
m4_df <- m4_df[-c(4,9,14), ]

dw3<-dwplot(m4_df, dot_args = list(aes(shape = model)),
            whisker_args = list(aes(linetype = model)))+
  geom_vline(xintercept = 0, colour = "red", linetype = 2) + 
  theme_bw() + xlab("Coefficient Estimate") +
  theme(legend.position = "top") +
  scale_colour_grey(start = .1, end = .1, name = "Model", labels = c("Brazil", "Chile", "Colombia")) +
  scale_shape_discrete(name = "Model",labels = c("Brazil", "Chile", "Colombia")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model")) +
  theme(axis.text=element_text(size=14))+
  theme(legend.text = element_text(size=14))


gp<-ggarrange(dw1 + rremove("xlab"), dw2 + rremove("xlab"), dw3 + rremove("xlab"), ncol = 3, nrow = 1, common.legend=TRUE)

annotate_figure(gp,bottom = textGrob("Coefficient Estimate", gp = gpar(cex = 1.3)))




